//
//  YSBaseThreeViewController.m
//  HubayMe1
//
//  Created by apple on 16/12/17.
//  Copyright © 2016年 Global Barter. All rights reserved.
//

#import "YSBaseThreeViewController.h"
#import "YSClassificationCell.h"

static CGFloat const margin = 5;
static NSInteger const cols = 3;
#define wh ((kScreenWidth - (cols - 1) * margin) / cols)


static NSString * const ID = @"ClassificationCell";
@interface YSBaseThreeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, weak)  UICollectionView *collectionView;

@end

@implementation YSBaseThreeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //2 设置底部的View
    [self setUpBottomView];
}

-(void)setUpBottomView{
    
    // tableView的底部视图 也属于tableView内容一部分
    
    // 创建布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    // 设置cell尺寸
    
    layout.itemSize = CGSizeMake(wh, wh);
    layout.minimumInteritemSpacing = margin;
    layout.minimumLineSpacing = margin;
    
    // 创建UICollectionView
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    _collectionView = collectionView;
    
    collectionView.showsVerticalScrollIndicator = NO;
    collectionView.dataSource = self;
    collectionView.delegate = self;
    collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    // 注册cell
    [collectionView registerNib:[UINib nibWithNibName:@"YSClassificationCell" bundle:nil] forCellWithReuseIdentifier:ID];
    
    
    // 设置tableView底部视图
    self.view = collectionView;
    collectionView.contentInset = UIEdgeInsetsMake(49, 0, 120, 0);
    
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    if (self.type.integerValue==1){
        return 19;
    }else if (self.type.integerValue==2){
        return 8;
    }else{
        return 29;
    }
    
    
}


#pragma mark - UICollectionViewDelegate
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YSClassificationCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    return cell;
}

// 点击cell就会调用
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}

@end
